package com.julis.activity.setting.updata;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.baseutils.SpfUtils;
import com.github.czy1121.view.RoundButton;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.julis.R;
import com.julis.init.MAIN;

/**
 * 远程升级设置
 */
public class Setting_IP_Activity extends AppCompatActivity {


    @BindView(R.id.img_back)
    RelativeLayout imgBack;
    @BindView(R.id.textView22)
    TextView textView22;
    @BindView(R.id.et_ip)
    EditText etIp;
    @BindView(R.id.textView23)
    TextView textView23;
    @BindView(R.id.et_port)
    EditText etPort;
    @BindView(R.id.bt_Start)
    RoundButton btGetCode;
    @BindView(R.id.activity_main)
    LinearLayout activityMain;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ipsz_);
        ButterKnife.bind(this);
        String ips2 = (String) SpfUtils.get(Setting_IP_Activity.this, "ip",
                MAIN.IP);
        etIp.setText("" + ips2);
        String ports2 = (String) SpfUtils.get(Setting_IP_Activity.this,
                "port", MAIN.Port);
        etPort.setText("" + ports2);
    }


    @OnClick({R.id.img_back, R.id.bt_Start})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.bt_Start:
                if (TextUtils.isEmpty(etIp.getText().toString())) {
                    Toast.makeText(this, "请输入Ip！", Toast.LENGTH_SHORT).show();
                    return;

                }
                if (TextUtils.isEmpty(etPort.getText().toString())) {
                    Toast.makeText(this, "请输入端口号！", Toast.LENGTH_SHORT).show();
                    return;

                }
                SpfUtils.put(Setting_IP_Activity.this, "ip",
                      ""+etIp.getText().toString());
                SpfUtils.put(Setting_IP_Activity.this, "port",
                        ""+etPort.getText().toString());
                Toast.makeText(this, "设置成功！", Toast.LENGTH_SHORT).show();
                break;
        }
    }
}
